<?php
//话题标签
defined('IN_TS') or die('Access Denied.');

switch($ts){

	//标签
	case "":
	
		$name = urldecode(trim($_GET['name']));

		$tagid = aac('tag')->getTagId(t($name));

		
		$strTag = $new['study']->find('tag',array(
		
			'tagid'=>$tagid,
		
		));

		$page = isset($_GET['page']) ? intval($_GET['page']) : 1;

		$url = tsUrl('study','tag',array('name'=>urlencode($name),'page'=>''));

		$lstart = $page*30-30;

		$arrTagId = $new['study']->findAll('tag_study_index',array(
		
			'tagid'=>$tagid,
		
		),null,null,$lstart.',30');
		
		$tagNum = $new['study']->findCount('tag_study_index',array(
			'tagid'=>$tagid,
		));

		$pageUrl = pagination($tagNum, 30, $page, $url);

		foreach($arrTagId as $key=>$item){

			$arrStudys[] = $new['study']->find('study',array(
			
				'studyid'=>$item['studyid'],
				
			));
			
		}
		
		foreach($arrStudys as $key=>$item){	
			
			if($item['isaudit']==0){
			
				$arrStudy[] = $item;
				$arrStudy[$key]['user'] = aac('user')->getOneUser($item['userid']);
			
			}

		}
		

		//热门tag
		$arrTag = $new['study']->findAll('tag',"`count_sutyd`> '0'",null,null,30);

		$title = $strTag['tagname'].'热门课程列表';

		include template("tag");
	
		break;
	
	//标签列表
	case "list":
	
		$page = isset($_GET['page']) ? $_GET['page'] : '1';
		
		$url = tsUrl('study','tag',array('ts'=>'list','page'=>''));
		
		$lstart = $page*40-40;
		
		$arrTag = $new['study']->findAll('tag',"`count_study`!=''",null,null,$lstart.',40');
		
		$tagNum = $new['study']->findCount('tag',"`count_study`!=''");
		
		$pageUrl = pagination($tagNum, 40, $page, $url);
		
		$title = '标签';
		include template('tag_list');
	
		break;

}